/***********************************************************************
 * Module:  PlainTextBuilder.java
 * Author:  wuxinyang
 * Purpose: Defines the Class PlainTextBuilder
 ***********************************************************************/

package com.witframework.plugin.lucene.extractor;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.witframework.plugin.lucene.DocumentHandlerException;



/** PlainTextBuilder
 *
 * @pdOid 0d2fa84e-c1f1-4dee-9565-360fde6067a1 */
public class PlainTextExtractor implements InputStreamTextExtractor {

	public String getContents(InputStream is) throws DocumentHandlerException{
		StringBuilder contents = new StringBuilder();
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String line = null;
			while ((line = br.readLine()) != null) {
				contents.append(line).append("\n");
			}
			br.close();
		} catch (IOException e) {
			throw new DocumentHandlerException("Cannot read the text document",e);
		}
		return contents.toString();
	}
}